//
//  firstViewController.m
//  Test-ZhuangHaiPeng
//
//  Created by Hai Peng Zhuang on 12/16/15.
//  Copyright © 2015 itcast. All rights reserved.
//

#import "firstViewController.h"
#import "HPTestData.h"
#import "HPCell.h"
#import "secondViewController.h"
@interface firstViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *dataArray;
@end


@implementation firstViewController

- (NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [HPTestData data];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *ID = @"cell";
    HPCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[HPCell alloc] init];
    }
    
    HPTestData *data = self.dataArray[indexPath.row];
    cell.contentLabel.text = data.title;
    
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    secondViewController *secondVC = [[secondViewController alloc]init];
    HPTestData *data = self.dataArray[indexPath.row];
    secondVC.title = data.title;
    secondVC.content = data.content;
    [self.navigationController pushViewController:secondVC animated:YES];
    
    
    
    
}

@end
